﻿using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfApp_PrismDialog.Base;

namespace WpfApp_PrismDialog.ViewModels;

public class MainViewModel:BindableBase
{
    public DelegateCommand? OpenSubWindowCommand { get; set; }

    public DelegateCommand? OpenWindowForDialogService { get; set; }

    public DelegateCommand? OpenWindowForDialogServerParam { get; set; }

	public MainViewModel(IEventAggregator eventAggregator,IDialogService dialogService)
	{

        //打开事件总线消息打开弹窗
        OpenSubWindowCommand = new DelegateCommand(() => 
        {
            eventAggregator.GetEvent<OpenWindowBus>().Publish("");
        });

        //通过IDialogService打开窗口
        OpenWindowForDialogService = new DelegateCommand(() => 
        {
            dialogService.ShowDialog("UCDetail",new Action<IDialogResult>(OnSubDialogClosed));
        });

        //通过IDialogService打开窗口并携带参数
        OpenWindowForDialogServerParam = new DelegateCommand(() => 
        {
            DialogParameters dialogParam = new DialogParameters();
            dialogParam.Add("username", "tom");
            dialogParam.Add("password", "a");
            dialogService.ShowDialog("UCDetail", dialogParam, dialogResult => 
            {
                
            });
        });
    }

    private void OnSubDialogClosed(IDialogResult dialogResult)
    { 
        
    }
}
